"""
 encoding    : utf-8
 @File       : current_page.py
 @Author     : jiahong
 @Version    :
 @Description:
 @Date       : 2024/07/10
"""
from auto_code.common.loginpage import *
from time import sleep
class CurrentTaskPage(LoginPage):
    def get_current_task(self):
        self.browser.find_element(by='css selector', value='li.ant-menu-submenu:nth-child(2) > div:nth-child(1) > span:nth-child(1) > i:nth-child(1)').click()

    def get_new_resource(self):
        self.browser.find_element(by='css selector', value='[href="#/recruitTrack/list/1"]').click()

    def click_query(self):
        self.browser.find_element(by='css selector', value='button.ant-btn:nth-child(1)').click()

    def send_name(self, name):
        self.browser.find_element(by='css selector', value='#name').send_keys(name)

    def choice_degree(self, degree):
        if degree:
            self.browser.find_element(by='css selector', value='#degree > div:nth-child(1) > div:nth-child(1)').click()
            elements = self.browser.find_elements(by='xpath', value='/html/body/div/div/div/div/ul/li')
            for element in elements:
                if degree == element.text.strip():
                    element.click()

    def choice_channel(self, channel):
        if channel:
            self.browser.find_element(by='css selector',
                                      value='#channelId > div:nth-child(1) > div:nth-child(1) > div:nth-child(1)').click()
            elements = self.browser.find_elements(by='xpath', value='/html/body/div/div/div/div/ul/li')
            for element in elements:
                if channel == element.text.strip():
                    element.click()

    def choice_sex(self, sex):
        if sex:
            self.browser.find_element(by='css selector',
                                      value='#sex > div:nth-child(1) > div:nth-child(1) > div:nth-child(1)').click()
            elements = self.browser.find_elements(by='xpath', value='/html/body/div/div/div/div/ul/li')
            for element in elements:
                if sex == element.text.strip():
                    element.click()

    def choice_product_line(self, line):
        if line:
            self.browser.find_element(by='css selector',
                                      value='#trainType > div:nth-child(1) > div:nth-child(1)').click()
            elements = self.browser.find_elements(by='xpath', value='/html/body/div/div/div/div/ul/li')
            for element in elements:
                if line == element.text.strip():
                    element.click()

    def send_phone(self, phone):
        self.browser.find_element(by='css selector', value='[placeholder="请输入手机号"]').send_keys(phone)

    def send_hr(self, hr):
        self.browser.find_element(by='css selector', value='[placeholder="请输入人事专员"]').send_keys(hr)

    def send_age_range(self, start_age, end_age):
        self.browser.find_element(by='css selector', value='[placeholder="Mini"]').send_keys(start_age)
        self.browser.find_element(by='css selector', value='[placeholder="Max"]').send_keys(end_age)

    def click_confirm(self):
        self.browser.find_element(by='css selector', value='.ant-modal-footer > div:nth-child(1) > button:nth-child(2)').click()

    def click_reset(self):
        self.browser.find_element(by='css selector', value='.ant-modal-footer > div:nth-child(1) > button:nth-child(1)').click()


if __name__ == '__main__':
    current_task = CurrentTaskPage(Firefox)
    current_task.input_username('admin')
    current_task.input_password('123456')
    current_task.input_verification_code()
    current_task.click_login_button()
    current_task.get_current_task()
    current_task.get_new_resource()
    current_task.click_query()
    current_task.send_name('马志元')
    current_task.choice_degree('高中')
    current_task.choice_channel('招聘会')
    current_task.choice_sex('女')
    current_task.choice_product_line('全部')
    current_task.send_phone(123456678)
    current_task.send_hr('啊马志元')
    current_task.send_age_range(10, 12)
    current_task.click_reset()
    current_task.click_confirm()
    sleep(2)
    current_task.browser.close()
